package com.base.core.framework.typehandle;

import java.lang.reflect.Field;
import java.util.List;

import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.MappedJdbcTypes;
import org.apache.ibatis.type.MappedTypes;

import com.baomidou.mybatisplus.extension.handlers.AbstractJsonTypeHandler;
import com.gitee.magic.context.ConverterEditorUtils;
import com.gitee.magic.core.json.JsonArray;

@MappedTypes({List.class })
@MappedJdbcTypes(JdbcType.VARCHAR)
public class ListStringTypeHandler extends AbstractJsonTypeHandler<List<String>> {

	public ListStringTypeHandler(Class<?> type) {
		super(type);
	}

	public ListStringTypeHandler(Class<?> type, Field field) {
		super(type, field);
	}

	@Override
	public List<String> parse(String json) {
		return ConverterEditorUtils.restoreList(String.class,new JsonArray(json));
	}

	@Override
	public String toJson(List<String> obj) {
		return ConverterEditorUtils.converter(obj).toString();
	}
	
}
